<?php
class Sign_up extends CI_Model {


   function __construct()
   {
         parent::__construct();
   }
    
    
    function sign_up($data)
    {
         $this->db->insert('user',$data); 
         return; 
    }

    function sign_in($email, $pass)
    {        

        $this->db->where('email',$email);
        $this->db->where('pass',$pass);
        $result = $this->db->get('user');

        if($result->num_rows())
        {
            $user = $result->result();
            $user['log_in'] = true;
            return $user;
        }
        else
        {
            $user['log_in'] = false; 
            return $user;
        }

    }
    
    function update_name($id,$name)
    {
        $this->db->where('user_id',$id);
        $this->db->update('user',array('full_name' => $name));
    }
    
    function update_number($id,$num)
    {
        $this->db->where('user_id',$id);
        $this->db->update('user',array('contact' => $num));
    }
    
    function image_path_to_delete($id)
    {
       
     $this->db->select('dp'); 
     $this->db->from('user');   
     $this->db->where('user_id',$id);
     $result = $this->db->get();
     foreach ($result->result_array() as $row)
     {
         return $row['dp'];
     }
    }	
    
    
    function forgot_pass($email)
    {
       
     $this->db->select('pass'); 
     $this->db->from('user');   
     $this->db->where('email',$email);
     $result = $this->db->get();
     foreach ($result->result_array() as $row)
     {
         return $row['email'];
     }
    }	
    
    
    function user_data($email)
    {        
        $this->db->where('email',$email);
        $result = $this->db->get('user');
        $user = $result->result();
        return $user;
    }
    
    function check_old_pass($old,$id,$new)
    {
        $this->db->where('user_id',$id);
        $query=$this->db->get('user');
        foreach ($query->result() as $row)
        {

                if($row->pass==$old)
            {
                $this->db->where('user_id',$id);
                $this->db->update('user',array('pass' => $new));
                $response = "";
                $response = "<div class='alert alert-success' role='alert' style='width:30%; margin-left:10px; margin-top:10px;''>Password Changed</div>";
            }
            else
            {
                $response = "";
                $response = "<div class='alert alert-danger' role='alert' style='width:35%; margin-left:10px; margin-top:10px;''>Incorrect Old Password</div>";
            }
        }
        echo $response;
        
        
    }
    function update_dp($file_path,$user_id)
    {
        $this->db->where('user_id',$user_id);
        $this->db->update('user',array('dp' => $file_path));
    }	
    function check_user_ava($u)
    {
         
        $response = "";
        $this->db->where('email',$u);
        $query=$this->db->get('user');
        if($query->num_rows()>0)
        {
            $user['email'] = false;
            return $user;
        }
         else
         {
            $user['email'] = true;
            return $user;
         }
    }
    
  
}
?>